﻿using GN.Pay.TradeChannel.DefaultImpl;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GN.Pay.TradeChannel.WeiXin.Response
{
    [Serializable]
    public class QueryResponse : AResponse
    {
        /// <summary>
        /// 查询响应
        /// </summary>
        private readonly ITradeChannel channel;

        public QueryResponse(string xmlString,
            ITradeChannel channel) : base(xmlString)
        {
            this.channel = channel;
        }

        /// <summary>
        /// 单位分  金额 标价币种
        /// </summary>
        public decimal Total_Fee { get; set; }

        /// <summary>
        /// 现金支付金额
        /// </summary>
        public decimal Cash_Fee { get; set; }

        /// <summary>
        /// 微信支付订单号
        /// </summary>
        public string Transaction_Id { get; set; }

        /// <summary>
        /// 订单号
        /// </summary>
        public string Out_Trade_No { get; set; }

        /// <summary>
        /// 支付完成时间
        /// </summary>
        public string Time_End { get; set; }

        /// <summary>
        /// 交易状态描述
        /// </summary>
        public string Trade_State_Desc { get; set; }
        /// <summary>
        /// 转为结果
        /// </summary>      
        /// <returns></returns>
        public ITradeOrderQueryResult ToResult()
        {
            var msg = "";
            if (!this.IsFullSuccess() || string.IsNullOrWhiteSpace(Transaction_Id))
            {
                msg = this.Err_Code_Des;
                return null;
            }        
            return new TradeOrderQueryResult(this.channel)
            {
                TradeNo = Transaction_Id,
                OrderNo = Out_Trade_No,
                OrderMoney = Convert.ToDecimal(Convert.ToInt32(Total_Fee) / 100),
                PayTime = FormatTime(Time_End, "yyyyMMddHHmmss"),
                PayFee = 0m,
            };
        }
    }
}
